package com.woniuxy.dao;

import com.mysql.jdbc.util.LRUCache;
import com.woniuxy.pojo.Dept;
import com.woniuxy.provider.DeptProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.cache.decorators.LruCache;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
@CacheNamespace(eviction = LruCache.class,flushInterval = 60000,size = 512,readWrite = false)
//@CacheNamespace相当于XML映射文件中<cache>
public interface DeptMapper {
    @Select("SELECT * FROM dept")
    public List<Dept> selectDepts();
    @Insert("INSERT INTO dept(deptno,dname,loc)VALUES(#{deptno},#{dname},#{loc})")
    public void insertDept(Dept dept);
    @Delete("DELETE FROM dept WHERE deptno=#{deptno}")
    public void deleteDept(byte deptno);
    @Update("UPDATE dept SET dname=#{dname},loc=#{loc} WHERE deptno=#{deptno}")
    public void updateDept(Dept dept);
    @Results({
            @Result(property = "deptno",column = "deptno"),
            @Result(property = "dname",column = "dname"),
            @Result(property = "loc",column = "loc"),
            @Result(property = "emps",column = "deptno",
                    many = @Many(select = "com.woniuxy.dao.EmpMapper.selectEmpsByDeptno"))
    })
    @Select("SELECT * FROM dept WHERE deptno=#{deptno}")
    public Dept selectDeptByNo(byte deptno);
    @Select("SELECT * FROM dept WHERE deptno=#{deptno}")
    public Dept selectDeptByNoStep(byte deptno);
    @UpdateProvider(type = DeptProvider.class,method = "update")
    public void updateDeptWithDynamicSQL(Dept dept);
}
